package org.lora.core.mybatis;

/**
 * <p>
 * Title:OracleDialect
 * </p>
 * <p>
 * Desription:Oracle SQL分页 方言
 * </p>
 * Create Time:2016年7月7日 下午2:31:05
 * 
 * @author Bladnir@outlook.com
 *         <p>
 *         History:
 *         </p>
 *         2016年7月7日 Bladnir Create</br>
 */
public class OracleDialect extends Dialect {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.mybatis.extend.interceptor.IDialect#getLimitString(java.lang.String,
	 * int, int)
	 */
	@Override
	public String getLimitString(String sql, int offset, int limit) {

		String tempSql = sql.trim();
		StringBuilder pagingSelect = new StringBuilder(tempSql.length() + 100);

		pagingSelect.append("select * from ( select row_.*, rownum rownum_ from ( ");
		pagingSelect.append(tempSql);
		pagingSelect.append(" ) row_ ) where rownum_ > ").append(offset).append(" and rownum_ <= ").append(offset + limit);

		return pagingSelect.toString();
	}

}